package com.al.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;

//@WebServlet("/sign/out")  等于 @WebServlet(value = "/sign/out") 
//注解 WebServlet 的 urlPatterns 属性与 value 属性作用相同，都用来设置映射路径
@WebServlet(urlPatterns = "/sign/out",name = "test")//可以不写name属性，默认全类名
public class SignOutServlet implements Servlet {
private ServletConfig config;
	
	@Override
	public void init(ServletConfig config) throws ServletException {
		System.out.println("初始化:"+this);
		this.config = config;
	}
	
	@Override
	public void service(ServletRequest req, ServletResponse resp) throws ServletException, IOException {
		System.out.println(config.getServletName()+"提供服务("+this+")");
		
		//获取一个字符打印流（来自 io 包）
		PrintWriter out = resp.getWriter();
		out.print("<div style='test-align:center; border: 1px solid blue; padding: 10px'>");
		out.print(this);
		out.print("</div>");
	}


	@Override
	public void destroy() {
		System.out.println(this+"销毁");
	}

	@Override
	public ServletConfig getServletConfig() {
		return this.config;
	}

	@Override
	public String getServletInfo() {
		return config.getServletName();
	}

}
